package com.manor.paradise.fragment

import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import com.manor.common.fragment.BaseFragment
import com.manor.common.ktx.setBindViewPager
import com.manor.paradise.R
import com.manor.paradise.adapter.VP2Adapter
import kotlinx.android.synthetic.main.fragment_reik_index.*

/**
 * 灵气指数
 */
class ReikiIndexFragment : BaseFragment() {
    private var mAdapter: VP2Adapter? = null
    private var isHire = false
    private var isAuth = false


    companion object {
        fun newInstance(isHire: Boolean): ReikiIndexFragment {
            val args = bundleOf("isHire" to isHire)
            val fragment = ReikiIndexFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun getLayoutRes(): Int = R.layout.fragment_reik_index


    override fun initView() {
        isHire = arguments?.getBoolean("isHire") ?: false

        val fragmentList: MutableList<Fragment> = if (isHire) {
            mutableListOf(
                    ReikiSubFragment.newInstance(isHire, isAchieve = true, isAuth = false),
                    ReikiSubFragment.newInstance(isHire, isAchieve = false, isAuth = false)
            )
        } else {
            mutableListOf(
                    ReikiSubFragment.newInstance(isAuth, isAchieve = false, isAuth = true),
                    ReikiSubFragment.newInstance(isAuth, isAchieve = false, isAuth = false)
            )
        }


        mAdapter = VP2Adapter(this, fragmentList)
        viewPager.offscreenPageLimit = 2
        viewPager.adapter = mAdapter

        tabLayout.setBindViewPager(viewPager, if (isHire) { listOf("已完成任务", "未完成任务") } else { listOf("已认证", "未认证") })
    }

}